/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {TreeNode} subRoot
 * @return {boolean}
 */
 var isSubtree = function(root, subRoot) {
    const isSame = function(left,right){
      if(left === null && right === null){
        return true
      }
      if(left === null || right === null){
        return false
      }
      if(left.val !== right.val){
        return false
      }
      return isSame(left.left,right.left) && isSame(left.right,right.right)
    }
    let queue = []
    let cur = null
    queue.push(root)
    while(queue.length){
      cur = queue.shift()
      if(isSame(cur,subRoot)){
        return true
      }
      cur.left && queue.push(cur.left)
      cur.right && queue.push(cur.right)
    }
    return false
};